﻿using AutoMapper;
using MediatR;
using Traceability.App.Applications.Command.Health;
using Traceability.Domain.Entity;
using Traceability.Domain.Repository;
using Traceability.Enum;

namespace Traceability.App.Applications.CommandHand.Health
{
    public class AddHealthCommandHandler : IRequestHandler<AddHealthCommand, ApiResult<int>>
    {

        private readonly IBaseRepository<HealthModel> _health;
        private readonly IMapper mapper;

        public AddHealthCommandHandler(IBaseRepository<HealthModel> health, IMapper mapper)
        {
            _health = health;
            this.mapper = mapper;
        }

        public Task<ApiResult<int>> Handle(AddHealthCommand request, CancellationToken cancellationToken)
        {
           var result=new ApiResult<int>();
                var helath=mapper.Map<HealthModel>(request);
            helath.id = 0;
            _health.Add(helath);
            result.Message = "添加成功";
            


            return Task.FromResult(result);
        }
    }
}
